
package cn.hz.camel;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Collectors;
 

 

public   class MzHandleBook extends MzHandle {
  
   
   private int start=0;	
   public   List<Object> handle(){
	   start=start+1000;
	   List<Map<String, Object>> listOfMaps= inClient.executeQuery("select id,title,author,price,stat from book limit "+start+" , 1000;");
	  
	   List<Object> listOfObjects = listOfMaps.stream()
               .collect(Collectors.toList());
	   //System.out.println(listOfObjects.size());
	   return listOfObjects;
   }
   
   

   public   boolean outHandle(MzResObj obj){
	   List<Object> listOfObjects=obj.getObjs();
	 
	   List<Map<String, Object>> listOfMaps = listOfObjects.stream()
			    .filter(obj2 -> obj2 instanceof Map)
			    .map(obj2 -> (Map<String, Object>) obj2)
			    .collect(Collectors.toList());
	   String sql=MzTools.generateBatchInsertSQL(listOfMaps, "book");
	   outClient.executInsert(sql );
	   System.out.println(sql);
	   return true;
   }
   public   boolean resHandle(MzResObj obj){
	   System.out.println(obj); 
	   List<Object> bjs=obj.getObjs(); 
	   String ids="";
		for( Object o:bjs){
			Map<String,Object> map=(Map<String,Object>)o;
			if(!ids.equals("")){
				ids=ids+",";
			}
			ids=ids+map.get("id");
		} 
		
	   System.out.println(ids);
	   if(ids.length()>0){
		   inClient.executInsert("update book set stat=3 where id in ("+ids+")");
	   }
	   
	   return true;
   }
   
    }
